package com.example.medicalrecord.AggregationModule.administrator.controller;


import com.example.medicalrecord.AggregationModule.administrator.pojo.dto.AdminDoctorAddParam;
import com.example.medicalrecord.AggregationModule.administrator.pojo.dto.AdminDoctorQuery;
import com.example.medicalrecord.AggregationModule.administrator.pojo.dto.AdministratorParam;
import com.example.medicalrecord.AggregationModule.administrator.pojo.dto.AdministratorQuery;
import com.example.medicalrecord.AggregationModule.administrator.pojo.vo.AdminDoctorVO;
import com.example.medicalrecord.AggregationModule.administrator.service.AdministratorService;
import com.example.medicalrecord.base.response.JsonResult;
import com.example.medicalrecord.base.response.PageData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/admin/")
public class AdministratorController {

    @Autowired
    AdministratorService administratorService;

    /*查询管理员数据*/
    @GetMapping("admin/select")
    public JsonResult selectAdmin(AdministratorQuery administratorQuery){
        log.debug("查询所有管理员:administratorQuery={}",administratorQuery);
        PageData pageData = administratorService.selectAdmin(administratorQuery);
        return JsonResult.ok(pageData);
    }

    /*添加管理员数据*/
    @PostMapping("admin/save")
    public JsonResult saveAdmin(AdministratorParam administratorParam){
        log.debug("添加管理员:administratorParam={}",administratorParam);
        administratorService.saveAdmin(administratorParam);
        return JsonResult.ok();
    }
    /*删除管理员数据*/
    @PostMapping("admin/delete/{id}")
    public JsonResult deleteAdmin(@PathVariable Long id){
        log.debug("删除管理员:id={}",id);
        administratorService.deleteAdmin(id);
        return JsonResult.ok();
    }

    /*查询医生数据*/
    @GetMapping("doctor/select")
    public JsonResult selectDoctor(AdminDoctorQuery adminDoctorQuery){
        log.debug("控制层医生管理参数={}",adminDoctorQuery);
        List<AdminDoctorVO> list = administratorService.selectDoctor(adminDoctorQuery);
        log.debug("查询数据:list=>{}",list);
        return JsonResult.ok(list);
    }
    /*新建医生账号*/
    @PostMapping("doctor/add")
    public JsonResult addDoctor(AdminDoctorAddParam adminDoctorAddParam){
        log.debug("创建医生账号参数={}",adminDoctorAddParam);
        administratorService.addDoctor(adminDoctorAddParam);
        return JsonResult.ok();
    }
    /*修改用户状态*/
    @PostMapping("updateStatus/{doctorId}/{expert}")
    public JsonResult updateStatus (@PathVariable Long doctorId,@PathVariable String expert){
        log.debug("修改用户状态,doctorId={},expert={}",doctorId,expert);
        administratorService.updateStatus(doctorId,expert);
        return JsonResult.ok();
    }
    /*医生密码重置*/
    @PostMapping("/doctor/password/{doctorId}")
    public JsonResult resetPassword (@PathVariable Long doctorId){
        log.debug("密码重置:doctorId={}",doctorId);
        administratorService.resetPassword(doctorId);
        return JsonResult.ok();
    }
    /*医生账号删除*/
    @PostMapping("/doctor/delete/{doctorId}")
    public JsonResult deleteDoctor(@PathVariable Long doctorId){
        log.debug("删除医生账号:doctorId=>{}",doctorId);
        administratorService.deleteDoctor(doctorId);
        return JsonResult.ok();
    }

}
